<template>
<view class="content">
	<view :style='{"minHeight":"100vh","padding":"0px 0 80rpx","borderColor":"#21d5ae","background":"url(http://codegen.caihongy.cn/20230301/28586bd575de4721a42223a6e1d4b118.png) fixed","borderWidth":"0px 0 0","width":"100%","position":"relative","borderStyle":"dashed","height":"auto"}'>
		<form :style='{"width":"100%","padding":"60rpx 40rpx","background":"none","height":"auto"}' class="app-update-pv">
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">订单编号</view>
				<input :style='{"border":"0","padding":"0px 20rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255, 255, 255, 0)","fontSize":"28rpx"}' :disabled="ro.dingdanbianhao" v-model="ruleForm.dingdanbianhao" placeholder="订单编号"></input>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">目的地</view>
				<input :style='{"border":"0","padding":"0px 20rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255, 255, 255, 0)","fontSize":"28rpx"}' :disabled="ro.mudedi" v-model="ruleForm.mudedi" placeholder="目的地"></input>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">用户名</view>
				<input :style='{"border":"0","padding":"0px 20rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255, 255, 255, 0)","fontSize":"28rpx"}' :disabled="ro.yonghuming" v-model="ruleForm.yonghuming" placeholder="用户名"></input>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">代驾费用</view>
				<input :style='{"border":"0","padding":"0px 20rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255, 255, 255, 0)","fontSize":"28rpx"}' :disabled="ro.daijiafeiyong" v-model="ruleForm.daijiafeiyong" placeholder="代驾费用"></input>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">路线规划</view>
				<input :style='{"border":"0","padding":"0px 20rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255, 255, 255, 0)","fontSize":"28rpx"}' :disabled="ro.luxianguihua" v-model="ruleForm.luxianguihua" placeholder="路线规划"></input>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class=" select">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">代驾状态</view>
				<picker :style='{"width":"100%","flex":"1","height":"auto"}' @change="daijiazhuangtaiChange" :value="daijiazhuangtaiIndex"  :range="daijiazhuangtaiOptions">
					<view :style='{"width":"100%","lineHeight":"120rpx","fontSize":"28rpx","color":"#666"}' class="uni-input">{{ruleForm.daijiazhuangtai?ruleForm.daijiazhuangtai:"请选择代驾状态"}}</view>
				</picker>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class=" select">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">服务评价</view>
				<picker :style='{"width":"100%","flex":"1","height":"auto"}' @change="fuwupingjiaChange" :value="fuwupingjiaIndex" :disabled="true" :range="fuwupingjiaOptions">
					<view :style='{"width":"100%","lineHeight":"120rpx","fontSize":"28rpx","color":"#666"}' class="uni-input">{{ruleForm.fuwupingjia?ruleForm.fuwupingjia:"请选择服务评价"}}</view>
				</picker>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">更新时间</view>
				<input :style='{"border":"0","padding":"0px 20rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255, 255, 255, 0)","fontSize":"28rpx"}' v-model="ruleForm.gengxinshijian" placeholder="更新时间" @tap="toggleTab('gengxinshijian')"></input>
			</view>
			<view :style='{"padding":"0 20rpx 0px","boxShadow":"inset 0px 0px 0px 0px #f9edd9","margin":"0 0 20rpx","borderColor":"#f7d3ba","borderRadius":"0px","borderWidth":"0 0 6rpx","background":"#fff","display":"flex","width":"100%","lineHeight":"100rpx","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"160rpx","padding":"0 20rpx 0 0","fontSize":"28rpx","color":"#333","textAlign":"right"}' class="title">代驾账号</view>
				<input :style='{"border":"0","padding":"0px 20rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255, 255, 255, 0)","fontSize":"28rpx"}' :disabled="ro.daijiazhanghao" v-model="ruleForm.daijiazhanghao" placeholder="代驾账号"></input>
			</view>
			
			<!-- 否 -->
 

			
			
			<view :style='{"padding":"0","margin":"60rpx 0 0 0","background":"none","display":"flex","width":"100%","justifyContent":"center","height":"auto"}' class="btn" >
				<button :style='{"padding":"0 40rpx","boxShadow":"2rpx 8rpx 8rpx #ddd","margin":"0 40rpx 0 0","borderColor":"#fb9a40","color":"#333","display":"inline","minWidth":"200rpx","borderRadius":"0px","background":"linear-gradient(23deg, rgba(255,255,255,1) 0%, rgba(247,211,186,1) 100%)","borderWidth":"0px 6rpx","width":"auto","lineHeight":"72rpx","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}' @tap="onSubmitTap" class="bg-red">提交</button>
			</view>
		</form>

		<w-picker mode="dateTime" step="1" :current="false" :hasSecond="false" @confirm="gengxinshijianConfirm" ref="gengxinshijian" themeColor="#333333"></w-picker>
	</view>
</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";
    import xiaEditor from '@/components/xia-editor/xia-editor';
	export default {
		data() {
			return {
				cross:'',
				ruleForm: {
				dingdanbianhao: '',
				mudedi: '',
				yonghuming: '',
				daijiafeiyong: '',
				luxianguihua: '',
			        daijiazhuangtai: '进行中',
			        fuwupingjia: '未评价',
				gengxinshijian: '',
				daijiazhanghao: '',
				ispay: '',
				},
				daijiazhuangtaiOptions: [],
				daijiazhuangtaiIndex: 0,
				fuwupingjiaOptions: [],
				fuwupingjiaIndex: 0,
				// 登录用户信息
				user: {},
                ro:{
                   dingdanbianhao : false,
                   mudedi : false,
                   yonghuming : false,
                   daijiafeiyong : false,
                   luxianguihua : false,
                   daijiazhuangtai : false,
                   fuwupingjia : false,
                   gengxinshijian : false,
                   daijiazhanghao : false,
                   ispay : false,
                },
			}
		},
		components: {
			wPicker,
            xiaEditor
		},
		computed: {
			baseUrl() {
				return this.$base.url;
			},



		},
		async onLoad(options) {
            this.ruleForm.gengxinshijian = this.$utils.getCurDateTime();

			let table = uni.getStorageSync("nowTable");
			// 获取用户信息
			let res = await this.$api.session(table);
			this.user = res.data;
			
			// ss读取
			this.ruleForm.daijiazhanghao = this.user.daijiazhanghao
			this.ro.daijiazhanghao = true;

            this.ro.dingdanbianhao = true;
            this.ro.mudedi = true;
            this.ro.yonghuming = true;
            this.ro.fuwupingjia = true;
            this.ro.gengxinshijian = true;

			// 自定义下拉框值
			this.daijiazhuangtaiOptions = "进行中,已完成".split(',')
			// 自定义下拉框值
			this.fuwupingjiaOptions = "已评价,未评价".split(',')

			// 如果有登录，获取登录后保存的userid
			this.ruleForm.userid = uni.getStorageSync("userid")
			if (options.refid) {
				// 如果上一级页面传递了refid，获取改refid数据信息
				this.ruleForm.refid = options.refid;
				this.ruleForm.nickname = uni.getStorageSync("nickname");
			}
			// 如果是更新操作
			if (options.id) {
				this.ruleForm.id = options.id;
				// 获取信息
				res = await this.$api.info(`dingdanxinxi`, this.ruleForm.id);
				this.ruleForm = res.data;
			}
			// 跨表
			this.cross = options.cross;
			if(options.cross){
				var obj = uni.getStorageSync('crossObj');
				for (var o in obj){
					if(o=='dingdanbianhao'){
					this.ruleForm.dingdanbianhao = obj[o];
					this.ro.dingdanbianhao = true;
					continue;
					}
					if(o=='mudedi'){
					this.ruleForm.mudedi = obj[o];
					this.ro.mudedi = true;
					continue;
					}
					if(o=='yonghuming'){
					this.ruleForm.yonghuming = obj[o];
					this.ro.yonghuming = true;
					continue;
					}
					if(o=='daijiafeiyong'){
					this.ruleForm.daijiafeiyong = obj[o];
					this.ro.daijiafeiyong = true;
					continue;
					}
					if(o=='luxianguihua'){
					this.ruleForm.luxianguihua = obj[o];
					this.ro.luxianguihua = true;
					continue;
					}
					if(o=='daijiazhuangtai'){
					this.ruleForm.daijiazhuangtai = obj[o];
					this.ro.daijiazhuangtai = true;
					continue;
					}
					if(o=='fuwupingjia'){
					this.ruleForm.fuwupingjia = obj[o];
					this.ro.fuwupingjia = true;
					continue;
					}
					if(o=='gengxinshijian'){
					this.ruleForm.gengxinshijian = obj[o];
					this.ro.gengxinshijian = true;
					continue;
					}
					if(o=='daijiazhanghao'){
					this.ruleForm.daijiazhanghao = obj[o];
					this.ro.daijiazhanghao = true;
					continue;
					}
				}
			}
			this.styleChange()
		},
		methods: {
			styleChange() {
				this.$nextTick(()=>{
					// document.querySelectorAll('.app-update-pv . .uni-input-input').forEach(el=>{
					//   el.style.backgroundColor = this.addUpdateForm.input.content.backgroundColor
					// })
				})
			},

			// 多级联动参数


			// 日长控件选择日期时间
			gengxinshijianConfirm(val) {
				console.log(val)
				this.ruleForm.gengxinshijian = val.result;
				this.$forceUpdate();
			},

			// 下拉变化
			daijiazhuangtaiChange(e) {
				this.daijiazhuangtaiIndex = e.target.value
				this.ruleForm.daijiazhuangtai = this.daijiazhuangtaiOptions[this.daijiazhuangtaiIndex]
			},
			// 下拉变化
			fuwupingjiaChange(e) {
				this.fuwupingjiaIndex = e.target.value
				this.ruleForm.fuwupingjia = this.fuwupingjiaOptions[this.fuwupingjiaIndex]
			},


			getUUID () {
				return new Date().getTime();
			},
			async onSubmitTap() {





















//跨表计算判断
				var obj;
				if((!this.ruleForm.daijiafeiyong)){
					this.$utils.msg(`代驾费用不能为空`);
					return
				}
				if(this.ruleForm.daijiafeiyong&&(!this.$validate.isIntNumer(this.ruleForm.daijiafeiyong))){
					this.$utils.msg(`代驾费用应输入整数`);
					return
				}
				if((!this.ruleForm.daijiazhuangtai)){
					this.$utils.msg(`代驾状态不能为空`);
					return
				}
				//更新跨表属性
			       var crossuserid;
			       var crossrefid;
			       var crossoptnum;
				if(this.cross){
					var statusColumnName = uni.getStorageSync('statusColumnName');
					var statusColumnValue = uni.getStorageSync('statusColumnValue');
					if(statusColumnName!='') {
                        if(!obj) {
						    obj = uni.getStorageSync('crossObj');
                        }
						if(!statusColumnName.startsWith("[")) {
							for (var o in obj){
								if(o==statusColumnName){
									obj[o] = statusColumnValue;
								}

							}
							var table = uni.getStorageSync('crossTable');
							await this.$api.update(`${table}`, obj);
						} else {
						       crossuserid=Number(uni.getStorageSync('userid'));
						       crossrefid=obj['id'];
						       crossoptnum=uni.getStorageSync('statusColumnName');
						       crossoptnum=crossoptnum.replace(/\[/,"").replace(/\]/,"");
						}
					}
				}
				if(crossrefid && crossuserid) {
					this.ruleForm.crossuserid=crossuserid;
					this.ruleForm.crossrefid=crossrefid;
					let params = {
						page: 1,
						limit:10,
						crossuserid:crossuserid,
						crossrefid:crossrefid,
					}
					let res = await this.$api.list(`dingdanxinxi`, params);
					if (res.data.total >= crossoptnum) {
						this.$utils.msg(uni.getStorageSync('tips'));
						return false;
					} else {
                //跨表计算
						if(this.ruleForm.id){
							await this.$api.update(`dingdanxinxi`, this.ruleForm);
						}else{
							await this.$api.add(`dingdanxinxi`, this.ruleForm);
						}
						this.$utils.msgBack('提交成功');
					}
				} else {
                //跨表计算
					if(this.ruleForm.id){
						await this.$api.update(`dingdanxinxi`, this.ruleForm);
					}else{
						await this.$api.add(`dingdanxinxi`, this.ruleForm);
					}
					this.$utils.msgBack('提交成功');
				}
			},
			optionsChange(e) {
				this.index = e.target.value
			},
			bindDateChange(e) {
				this.date = e.target.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			toggleTab(str) {
				this.$refs[str].show();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: calc(100vh - 44px);
		box-sizing: border-box;
	}
</style>
